<template>
  <div class="footer-wrapper">
    <!-- 页脚区域 -->
    <footer class="footer">
      <div class="footer-container">
        <!-- 顶部信息区：机构名称 -->
        <div class="footer-top">
          <div class="footer-brand">
            <h3 class="brand-name">全景智能安防与多模态大模型实验室</h3>
            <p class="brand-english">
              JPSMAI（Joint Research Lab on Panoramic Intelligent Surveillance and Multimodal Large Models）
            </p>
          </div>
        </div>

        <!-- 中间联系信息区 -->
        <div class="footer-contact">
          <div class="contact-item">
            <span class="contact-label">地址：</span>
            <span class="contact-value">辽宁省抚顺市望花区丹东路西段一号</span>
          </div>
          <div class="contact-item">
            <span class="contact-label">电话：</span>
            <span class="contact-value">17696645664（赵老师）</span>
          </div>
          <div class="contact-item">
            <span class="contact-label">邮箱：</span>
            <span class="contact-value">782049502@qq.com</span>
          </div>
        </div>

        <!-- 底部版权区 -->
        <div class="footer-bottom">
          <div class="copyright">全景智能安防与多模态大模型实验室</div>
        </div>
      </div>
    </footer>

    <!-- 申请试用弹窗（保持原有功能，优化样式贴合整体风格） -->
    <div v-if="showApplicationModal" class="modal-overlay" @click="closeModal">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>留下您的需求，我们会尽快与您联系</h3>
        </div>
        <div class="modal-body">
          <form @submit.prevent="submitApplication">
            <div class="form-row">
              <div class="form-group">
                <label for="name">* 名称</label>
                <input type="text" id="name" v-model="formData.name" required />
              </div>
              <div class="form-group">
                <label for="phone">* 联系电话</label>
                <input type="tel" id="phone" v-model="formData.phone" required />
              </div>
            </div>
            <div class="form-row">
              <div class="form-group">
                <label for="company">* 公司名称</label>
                <input type="text" id="company" v-model="formData.company" required />
              </div>
              <div class="form-group">
                <label for="position">* 职务</label>
                <input type="text" id="position" v-model="formData.position" required />
              </div>
            </div>
            <div class="form-group">
              <label for="startDate">* 试用时间</label>
              <div class="input-with-icon">
                <input type="text" ref="startDateInput" v-model="formData.startDate" required class="flatpickr-input" />
              </div>
            </div>
            <div class="form-group">
              <label for="description">* 需求描述</label>
              <textarea
                id="description"
                v-model="formData.description"
                placeholder="请输入您的需求描述..."
                maxlength="200"
                required
              ></textarea>
              <div class="char-count">{{ formData.description.length }}/200</div>
            </div>
            <div class="form-group">
              <label class="checkbox-container">
                <input type="checkbox" v-model="formData.agreePrivacy" />
                <span>我已阅读并同意 <a href="#" class="privacy-link">《隐私政策申明》</a></span>
              </label>
            </div>
            <div class="form-actions">
              <button type="button" class="btn-cancel" @click="closeModal">取消</button>
              <button type="submit" class="btn-submit">立即提交</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import flatpickr from 'flatpickr';
import 'flatpickr/dist/flatpickr.min.css';

export default {
  name: 'AppFooter',
  data() {
    return {
      showApplicationModal: false,
      formData: {
        name: '',
        phone: '',
        company: '',
        position: '',
        startDate: '',
        description: '',
        agreePrivacy: false
      },
      flatpickrInstance: null,
      scrollTimer: null
    }
  },
  methods: {
    closeModal() {
      this.showApplicationModal = false;
      this.resetForm();
    },
    submitApplication() {
      if (!this.formData.agreePrivacy) {
        alert('请阅读并同意隐私政策');
        return;
      }
      console.log('提交的数据:', this.formData);
      alert('申请提交成功，我们将尽快与您联系！');
      this.closeModal();
    },
    handleScroll() {
      if (this.scrollTimer) clearTimeout(this.scrollTimer);
      this.scrollTimer = setTimeout(() => {
        this.showApplicationModal = false;
        this.resetForm();
      }, 100);
    },
    resetForm() {
      this.formData = {
        name: '',
        phone: '',
        company: '',
        position: '',
        startDate: '',
        description: '',
        agreePrivacy: false
      };
    },
    initFlatpickr() {
      this.$nextTick(() => {
        const input = this.$refs.startDateInput;
        if (!input) {
          console.error('未找到日期输入框元素');
          return;
        }
        if (this.flatpickrInstance) {
          this.flatpickrInstance.destroy();
        }
        this.flatpickrInstance = flatpickr(input, {
          dateFormat: 'Y-m-d',
          allowInput: true,
          defaultDate: new Date(),
          maxDate: 'today',
          onClose: (selectedDates) => {
            if (selectedDates.length > 0) {
              this.formData.startDate = selectedDates[0].toISOString().split('T')[0];
            }
          }
        });
      });
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll);
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handleScroll);
    if (this.scrollTimer) clearTimeout(this.scrollTimer);
    if (this.flatpickrInstance) {
      this.flatpickrInstance.destroy();
    }
  },
  watch: {
    showApplicationModal(val) {
      if (val) {
        this.initFlatpickr();
      } else {
        this.$nextTick(() => {
          if (this.flatpickrInstance) {
            this.flatpickrInstance.destroy();
            this.flatpickrInstance = null;
          }
        });
      }
    }
  }
}
</script>

<style scoped>
/* 页脚核心样式：贴合学术机构简洁正式风格 */
.footer {
  background-color: #030d26;
  color: #ffffff;
  padding: 0;
  font-size: 14px;
  width: 100%;
}

.footer-container {
  width: 100%;
  margin: 0 auto;
  padding: 40px 20px 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 顶部品牌区 - 完全居中 */
.footer-top {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-brand {
  text-align: center;
  max-width: 800px;
  width: 100%;
}

.brand-name {
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 600;
  color: #fff;
  margin: 0 0 10px 0;
  line-height: 1.3;
}

.brand-english {
  font-size: clamp(12px, 1.2vw, 14px);
  color: #fff;
  letter-spacing: 0.5px;
  line-height: 1.5;
  margin: 0;
  opacity: 0.9;
}

/* 联系信息区 - 居中对齐 */
.footer-contact {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 30px;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: 900px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 250px;
  max-width: 300px;
  justify-content: flex-start;
}

.contact-label {
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
}

.contact-value {
  color: #fff;
  opacity: 0.9;
}

/* 底部版权区 */
.footer-bottom {
  text-align: center;
  color: #fff;
  font-size: 12px;
  line-height: 1.8;
  width: 100%;
}

.copyright {
  opacity: 0.7;
}

/* 弹窗样式优化：更简洁正式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 4px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  margin: 0;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  flex: 1;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="tel"],
.form-group textarea,
.flatpickr-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}

.form-group textarea {
  height: 80px;
  resize: vertical;
}

.char-count {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
  text-align: right;
}

.checkbox-container {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  font-size: 13px;
}

.privacy-link {
  color: #0066cc;
  text-decoration: none;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-cancel {
  padding: 8px 16px;
  background-color: #f5f5f5;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: inline-block;
}

.btn-submit {
  padding: 8px 16px;
  background-color: #0066cc;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.btn-submit:hover {
  background-color: #0052aa;
}

/* 日历输入框样式优化 */
.flatpickr-input {
  background-image: none;
  padding-left: 12px;
}

/* 确保日历面板层级 */
:deep(.flatpickr-calendar) {
  z-index: 1001 !important;
}

/* 响应式适配 */
@media (max-width: 1200px) {
  .footer-container {
    padding: 35px 20px 20px;
  }

  .footer-contact {
    gap: 25px;
  }
}

@media (max-width: 768px) {
  .footer-container {
    padding: 30px 15px 15px;
  }

  .footer-top {
    margin-bottom: 25px;
    padding-bottom: 15px;
  }

  .footer-contact {
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 15px;
  }

  .contact-item {
    min-width: 100%;
    max-width: 100%;
    justify-content: center;
    text-align: center;
  }

  .brand-name {
    font-size: clamp(16px, 4vw, 20px);
  }

  .brand-english {
    font-size: clamp(11px, 2.5vw, 13px);
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .footer-container {
    padding: 25px 10px 15px;
  }

  .footer-contact {
    gap: 12px;
  }

  .contact-item {
    flex-direction: column;
    gap: 4px;
  }

  .contact-label {
    font-size: 13px;
  }

  .contact-value {
    font-size: 13px;
  }
}
</style>